#!/usr/bin/perl
# get_pinkey.cgi
# Attempt to start the netebbms processes

require '../netebbms-lib.pl';
use Net::Twitter::Lite;


# read argument in %in
&ReadParse();

&error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");  # need check!
&error("$text{'eacl_np'} $text{'eacl_papply'}") unless $access{'apply'};  # need check!


# check argument
&error_setup($text{'start_err'});  # need check!

if (length($in{'consumerkey'}) != 21) {
	&error($text{'twitterclient_consumerkey_emsg'});
}

if (length($in{'consumersecret'}) != 41) {
	&error($text{'twitterclient_consumersecret_emsg'});
}


# twitter authorization
my %consumer_tokens = (
	consumer_key => $in{'consumerkey'},
	consumer_secret => $in{'consumersecret'},
);

my $nt = Net::Twitter::Lite->new(%consumer_tokens);
my $auth_url = $nt->get_authorization_url();

$request_token = $nt->request_token;
$request_token_secret = $nt->request_token_secret;


# show header
&ui_print_header(undef, $text{'twitterclient_title'}, '', undef, 1, 1, undef, undef, << "HTML"
<script language=JavaScript type="text/javascript">
opener.document.configform.requesttoken.value = "$request_token";
opener.document.configform.requestsecret.value = "$request_token_secret";

document.location = "$auth_url";
</script>
HTML
);


# show footer
&ui_print_footer('', $text{'index_title'});

